import { getUserList } from '@/store/modules/userStore'
import { useEffect, useRef, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import '../test.css'
import * as echarts from 'echarts'

function Board() {
  const chartRef = useRef(null)
  let chartInstance = null
  const dispath = useDispatch()
  const { userInfo } = useSelector(state => state.user)

  useEffect(() => {
    dispath(getUserList())

    if (chartRef.current) {
      chartInstance = echarts.init(chartRef.current)
      const option = {
        title: {
          text: 'test month bill',
        },
        tooltip: {
          trigger: 'axis',
        },
        legend: {
          data: ['Step Start', 'Step Middle', 'Step End'],
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        },
        yAxis: {
          type: 'value',
        },
        series: [
          {
            name: 'Step Start',
            type: 'line',
            step: 'start',
            data: [120, 132, 101, 134, 90, 230, 210],
          },
          {
            name: 'Step Middle',
            type: 'line',
            step: 'middle',
            data: [220, 282, 201, 234, 290, 430, 410],
          },
          {
            name: 'Step End',
            type: 'line',
            step: 'end',
            data: [450, 432, 401, 454, 590, 530, 510],
          },
        ],
      }

      chartInstance.setOption(option)
    }

    return () => {
      console.log('leave')
      if (chartInstance) {
        // chartInstance.dispose()
      }
    }
  }, [])

  return (
    <div>
      <div className="title-desc">
        <div>名称：{userInfo.name}</div>
        <div>简介：{userInfo.desc}</div>
      </div>
      <div style={{ width: '100%', height: '600px' }} ref={chartRef}></div>
    </div>
  )
}

export default Board
